<template>
  <view class="flex items-center justify-between">
    <text style="color: #999999;font-size: 26rpx;float: left;display: block;max-width: 280rpx;line-height: 60rpx;">{{newObj.create_time}}</text>
    <view class="flex items-center">
      <view class="flex items-center" style="ine-height: 60rpx;margin-right: 10rpx;" @click="handleLikeClick">
        <image
        src="@/static/index/icon_like.png"
        style="width: 48rpx;height: 48rpx;margin-right: 6rpx;"
        mode="" v-if="newObj.like === 2"></image>
        <image
        src="@/static/index/icon_like1.png"
        style="width: 48rpx;height: 48rpx;margin-right: 6rpx;"
        mode="" v-else-if="newObj.like === 1"></image>
        <text style="color: #000000;font-size: 24rpx;margin-right: 14rpx;">
          {{newObj.like_num>10000?( (newObj.like_num/10000).toFixed(1)+'万' ):newObj.like_num || 0}}
        </text>
      </view>
      <view @click="tzxq(item.id)" class="flex items-center" style="line-height: 60rpx;margin-right: 10rpx;">
        <image
        src="@/static/index/icon_comment.png"
        style="width: 48rpx;height: 48rpx;margin-right: 6rpx;"
        mode=""></image>
        <text style="color: #000000;font-size: 24rpx;margin-right: 14rpx;">
          {{newObj.comment_num>10000?( (newObj.comment_num/10000).toFixed(1)+'万' ):newObj.comment_num || 0}}
        </text>
      </view>
      <view class="flex items-center" style="line-height: 60rpx;" @click="handleCollectClick">
        <image
        src="@/static/index/icon_collect.png"
        style="width: 48rpx;height: 48rpx;margin-right: 6rpx;"
        mode="" v-if="newObj.collect === 2"></image>
        <image
        src="@/static/index/icon_collect1.png"
        style="width: 48rpx;height: 48rpx;margin-right: 6rpx;"
        mode="" v-else-if="newObj.collect === 1"></image>
        <text style="color: #000000;font-size: 24rpx;">
          {{newObj.collect_num>10000?( (newObj.collect_num/10000).toFixed(1)+'万' ):newObj.collect_num || 0}}
        </text>
      </view>
    </view>
		<noLoginToast ref="noLoginToast"/>
  </view>
</template>

<script>
export default {
  name: 'commentCollentLike',
  props: {
    item: {
      type: Object,
      default: () => ({
        like_num: 0,
        comment_num: 0,
        collect_num: 0
      })
    }
  },
  watch: {
    item: {
      deep: true,
      handler(newVal, oldVal) {
        this.newObj = newVal
      },
      immediate: true
    }
  },
  data() {
    return {
      newObj: {},
      loading: false
    }
  },
  methods: {
    async handleLikeClick() {
      let isLogin = await this.$refs.noLoginToast.open()
      if (!isLogin) {
        return
      }
      if (this.loading) return
      this.loading = true
      let data = {
        voice_id: this.newObj.id
      }
      const {code} = await this.post('api/voice/like', data, true)
      this.loading = false
      if (code === 1) {
        this.newObj.like = this.newObj.like === 1 ? 2 : 1
        this.newObj.like_num = this.newObj.like === 1 ? this.newObj.like_num + 1 : this.newObj.like_num - 1
      }
    },
    async handleCollectClick() {
      let isLogin = await this.$refs.noLoginToast.open()
      console.log('%c [ isLogin ]-93', 'font-size:13px; background:pink; color:#bf2c9f;', isLogin)
      if (!isLogin) {
        return
      }
      if (this.loading) return
      this.loading = true
      console.log('%c [ this.loading ]-99', 'font-size:13px; background:pink; color:#bf2c9f;', this.loading)
      let data = {
        voice_id: this.newObj.id
      }
      const {code} = await this.post('api/voice/collect', data, true)
      this.loading = false
      if (code === 1) {
        this.newObj.collect = this.newObj.collect === 1 ? 2 : 1
        this.newObj.collect_num = this.newObj.collect === 1 ? this.newObj.collect_num + 1 : this.newObj.collect_num - 1
      }
    },
    // 帖子详情
    async tzxq(id) {
      uni.navigateTo({
        url: '/fenbao/pages/wenzhang/wzxq?id=' + id
      })
      return
			let isLogin = await this.$refs.noLoginToast.open()
      if (isLogin) {
        let isHasMobile = await this.$refs.noLoginToast.getPhoneNumber()
        console.log('%c [ isHasMobile ]-106', 'font-size:13px; background:pink; color:#bf2c9f;', isHasMobile)
        if (isHasMobile) {

        }
      }
    }
  }
}
</script>


<style scoped>
</style>